﻿package view.popup
{
    import cmd.*;
    import com.core.*;
    import com.sh.game.consts.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import manager.*;
    import morn.core.components.*;

    public class NewStallagePopUI extends View implements IDialogUI
    {
        public var closeBtn:Button;
        public var item_name:Label;
        public var textinput2:TextInput;
        public var yuanbao:Image;
        public var xiugaiBtn:Button;
        public var xiajiaBtn:Button;
        public var shangjiaBtn:Button;
        public var label1:Label;
        public var textinput1:TextInput;
        protected var uiXML:XML;
        private var data:Object;
        private var _Index:int;
        private var type:int;
        private var curCount:int = 1;
        private var maxCount:int;
        private var item:Loader;
        private var curNum:int = 0;
        private var background:Sprite;

        public function NewStallagePopUI()
        {
            this.uiXML = <View>r
n	t	t	t  <Image url=""png.common.cs2_tsbg"" x=""0"" y=""0"" width=""285"" height=""273"" sizeGrid=""10,50,10,10""/>r
n	t	t	t  <Button skin=""png.common.btn_cs2_close"" x=""252"" y=""5"" var=""closeBtn""/>r
n	t	t	t  <Label text=""label"" x=""76"" y=""128"" color=""0xffe4c7"" var=""item_name"" stroke=""1"" font=""SimSun"" width=""142"" height=""18"" align=""center""/>r
n	t	t	t  <Image url=""png.common.s9_itembg"" x=""92"" y=""185"" width=""140"" height=""33"" sizeGrid=""10,10,10,10""/>r
n	t	t	t  <TextInput x=""123"" y=""193"" width=""106"" height=""22"" color=""0x766b62"" font=""SimSun"" var=""textinput2"" editable=""true"" align=""center""/>r
n	t	t	t  <Image url=""png.common.cs2_yuanbao"" x=""101"" y=""193"" var=""yuanbao""/>r
n	t	t	t  <Button label=""修改"" skin=""png.common.btn_cs2_bag"" x=""43"" y=""224"" labelColors=""0xb29a6c,0xb29a6c,0xfff7af"" labelStroke=""1"" labelFont=""SimSun"" var=""xiugaiBtn""/>r
n	t	t	t  <Button label=""下架"" skin=""png.common.btn_cs2_bag"" x=""171"" y=""224"" labelColors=""0xb29a6c,0xb29a6c,0xfff7af"" labelStroke=""1"" labelFont=""SimSun"" var=""xiajiaBtn""/>r
n	t	t	t  <Button label=""上架"" skin=""png.common.btn_cs2_bag"" x=""109"" y=""224"" labelColors=""0xb29a6c,0xb29a6c,0xfff7af"" labelStroke=""1"" labelFont=""SimSun"" var=""shangjiaBtn""/>r
n	t	t	t  <Label text=""上架"" x=""124"" y=""4"" font=""Microsoft YaHei"" size=""15"" bold=""true"" color=""0xffeecd""/>r
n	t	t	t  <Image url=""png.common.s9_itembg"" x=""92"" y=""151"" width=""140"" height=""33"" sizeGrid=""10,10,10,10""/>r
n	t	t	t  <Label text=""单价"" x=""58"" y=""192"" color=""0xb9774b"" stroke=""1"" font=""SimSun"" var=""label1""/>r
n	t	t	t  <Label text=""数量"" x=""58"" y=""157"" color=""0xb9774b"" stroke=""1"" font=""SimSun""/>r
n	t	t	t  <TextInput x=""101"" y=""158"" width=""124"" height=""22"" color=""0x766b62"" font=""SimSun"" var=""textinput1"" editable=""true"" align=""center""/>r
n	t	t	t  <Image url=""jpg.common.cs2_bg3"" x=""109"" y=""52""/>r
n	t	t	t</View>")("<View>
			  <Image url="png.common.cs2_tsbg" x="0" y="0" width="285" height="273" sizeGrid="10,50,10,10"/>
			  <Button skin="png.common.btn_cs2_close" x="252" y="5" var="closeBtn"/>
			  <Label text="label" x="76" y="128" color="0xffe4c7" var="item_name" stroke="1" font="SimSun" width="142" height="18" align="center"/>
			  <Image url="png.common.s9_itembg" x="92" y="185" width="140" height="33" sizeGrid="10,10,10,10"/>
			  <TextInput x="123" y="193" width="106" height="22" color="0x766b62" font="SimSun" var="textinput2" editable="true" align="center"/>
			  <Image url="png.common.cs2_yuanbao" x="101" y="193" var="yuanbao"/>
			  <Button label="修改" skin="png.common.btn_cs2_bag" x="43" y="224" labelColors="0xb29a6c,0xb29a6c,0xfff7af" labelStroke="1" labelFont="SimSun" var="xiugaiBtn"/>
			  <Button label="下架" skin="png.common.btn_cs2_bag" x="171" y="224" labelColors="0xb29a6c,0xb29a6c,0xfff7af" labelStroke="1" labelFont="SimSun" var="xiajiaBtn"/>
			  <Button label="上架" skin="png.common.btn_cs2_bag" x="109" y="224" labelColors="0xb29a6c,0xb29a6c,0xfff7af" labelStroke="1" labelFont="SimSun" var="shangjiaBtn"/>
			  <Label text="上架" x="124" y="4" font="Microsoft YaHei" size="15" bold="true" color="0xffeecd"/>
			  <Image url="png.common.s9_itembg" x="92" y="151" width="140" height="33" sizeGrid="10,10,10,10"/>
			  <Label text="单价" x="58" y="192" color="0xb9774b" stroke="1" font="SimSun" var="label1"/>
			  <Label text="数量" x="58" y="157" color="0xb9774b" stroke="1" font="SimSun"/>
			  <TextInput x="101" y="158" width="124" height="22" color="0x766b62" font="SimSun" var="textinput1" editable="true" align="center"/>
			  <Image url="jpg.common.cs2_bg3" x="109" y="52"/>
			</View>;
            return;
        }// end function

        override protected function createChildren() : void
        {
            createView(this.uiXML);
            this.init();
            return;
        }// end function

        override protected function initialize() : void
        {
            super.initialize();
            return;
        }// end function

        public function init() : void
        {
            this.background = new Sprite();
            this.background.graphics.beginFill(0, 0.5);
            this.background.graphics.drawRect(0, 0, GlobalLayer.instance.root.stage.stageWidth, GlobalLayer.instance.root.stage.stageHeight);
            this.background.graphics.endFill();
            this.background.visible = false;
            this.background.addEventListener(MouseEvent.MOUSE_DOWN, this.onDown);
            PluginManager.instance.alertContainer.addChild(this.background);
            this.visible = false;
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            this.textinput1.text = "1";
            this.textinput1.maxChars = 10;
            this.textinput1.restrict = "0-9";
            this.textinput2.maxChars = 10;
            this.textinput2.restrict = "0-9";
            this.textinput1.addEventListener(MouseEvent.MOUSE_DOWN, this.doStop);
            this.textinput2.addEventListener(MouseEvent.MOUSE_DOWN, this.doStop);
            this.shangjiaBtn.addEventListener(MouseEvent.CLICK, this.onShangjia);
            this.xiugaiBtn.visible = false;
            this.xiugaiBtn.addEventListener(MouseEvent.CLICK, this.onXiugai);
            this.xiajiaBtn.visible = false;
            this.xiajiaBtn.addEventListener(MouseEvent.CLICK, this.onXiajia);
            this.closeBtn.addEventListener(MouseEvent.CLICK, this.onClose);
            this.data = null;
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.onDown);
            GlobalLayer.instance.root.addEventListener(Event.RESIZE, this.resizeHandler);
            return;
        }// end function

        private function doStop(event:MouseEvent) : void
        {
            event.stopPropagation();
            return;
        }// end function

        private function onDown(event:MouseEvent) : void
        {
            GlobalLayer.instance.flashStage.focus = null;
            return;
        }// end function

        private function onShangjia(event:MouseEvent) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_2:* = int(this.textinput2.text);
            if (_loc_2 < 1)
            {
                ModelProxy.change("movetips", "error", "请正确输入物品价格");
                return;
            }
            _loc_3 = 3;
            var _loc_5:* = int(this.textinput1.text);
            var _loc_6:* = ModelProxy.getValue("data", "bag");
            var _loc_7:* = ModelProxy.getValue("data", "bag")[this._Index];
            if (ModelProxy.getValue("data", "bag")[this._Index] != null && int(_loc_7[1]) < _loc_5)
            {
                ModelProxy.change("movetips", "error", "数据已更新，请重新上架");
                return;
            }
            _loc_4 = 0;
            PluginManager.instance.sendToServer("stallage", CMDStallage.AddItem, {index:this._Index, type:_loc_3, count:_loc_5, issinglesell:_loc_4, value:_loc_2});
            this.close();
            return;
        }// end function

        private function onXiugai(event:MouseEvent) : void
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_2:* = int(this.textinput2.text);
            if (_loc_2 < 1)
            {
                ModelProxy.change("movetips", "error", "请正确输入物品价格");
                return;
            }
            _loc_3 = 3;
            PluginManager.instance.sendToServer("stallage", CMDStallage.ChangeItem, {index:this._Index, type:_loc_3, issinglesell:_loc_4, value:_loc_2});
            this.close();
            return;
        }// end function

        private function onXiajia(event:MouseEvent) : void
        {
            PluginManager.instance.sendToServer("stallage", CMDStallage.FallItem, this._Index);
            this.close();
            return;
        }// end function

        public function show(param1:Object) : void
        {
            var _loc_5:int = 0;
            var _loc_2:* = param1[0];
            var _loc_3:* = param1[1];
            var _loc_4:int = 1;
            if (param1[2])
            {
                _loc_4 = param1[2];
            }
            this.type = _loc_4;
            this._Index = _loc_3;
            this.clean();
            this.data = _loc_2;
            if (this.data != null && int(this.data[4].bind) == 1)
            {
                ModelProxy.change("movetips", "error", "绑定物品不能交易");
                return;
            }
            if (this.type == 1)
            {
                this.shangjiaBtn.visible = true;
                this.label1.text = "单价";
            }
            else if (this.type == 2)
            {
                this.textinput1.text = String(this.data[1]);
                this.xiugaiBtn.visible = true;
                this.xiajiaBtn.visible = true;
                _loc_5 = int(this.data[6]);
                this.textinput2.text = String(_loc_5);
                this.curCount = this.data[7];
                this.label1.text = "单价";
            }
            var _loc_6:Boolean = true;
            this.visible = true;
            this.background.visible = _loc_6;
            this.drawItem();
            return;
        }// end function

        private function drawItem() : void
        {
            if (this.item)
            {
                this.item.parent.removeChild(this.item);
            }
            var imgURL:* = new URLRequest();
            imgURL.url = Config.getUrl("assets/images/icon/tools/" + this.data[4].icon + ".png", ResourceType.NORMAL);
            this.item = new Loader();
            this.item.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, function () : void
            {
                return;
            }// end function
            );
            this.item.load(imgURL);
            this.item.x = 93 + 22;
            this.item.y = 23 + 32;
            this.addChild(this.item);
            this.item_name.text = this.data[4].name;
            return;
        }// end function

        override public function set visible(param1:Boolean) : void
        {
            super.visible = param1;
            return;
        }// end function

        private function clean() : void
        {
            this.shangjiaBtn.visible = false;
            this.xiajiaBtn.visible = false;
            this.xiugaiBtn.visible = false;
            this.textinput2.text = "0";
            return;
        }// end function

        private function onClose(event:MouseEvent) : void
        {
            this.close();
            return;
        }// end function

        public function close() : void
        {
            var _loc_1:Boolean = false;
            this.visible = false;
            this.background.visible = _loc_1;
            this.data = null;
            return;
        }// end function

        private function resizeHandler(event:Event) : void
        {
            this.background.width = GlobalLayer.instance.root.stage.stageWidth;
            this.background.height = GlobalLayer.instance.root.stage.stageHeight;
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            return;
        }// end function

    }
}
